package com.pucheng.bracelet.ui.fragment.heartrate

import android.os.Bundle
import androidx.lifecycle.Observer
import com.pucheng.bracelet.R
import com.pucheng.bracelet.app.util.DatetimeUtil
import com.pucheng.bracelet.viewmodel.heartrate.AllDayHRToDayViewModel
import com.pucheng.bracelet.viewmodel.steps.StepsToDayViewModel
import kotlinx.android.synthetic.main.fragment_heartrate_to_day.*
import me.hgj.jetpackmvvm.base.fragment.BaseVmFragment

class AllDayHeartRateToDayFragment : BaseVmFragment<AllDayHRToDayViewModel>() {
    override fun createObserver() {
        mViewModel.apply {
            hertRateData.observe(viewLifecycleOwner, Observer {
                if (it!=null){
                    tv_heartrate.text = it.averageHR.toString()+getString(R.string.heartrate2)
                    tv_measure_date.text = DatetimeUtil.formatDate(
                        it.timestamp,
                        DatetimeUtil.DATE_PATTERN_A_H
                    )
                    hr_map.setData(it)
                }
            })
        }
    }

    override fun dismissLoading() {
    }

    override fun initView(savedInstanceState: Bundle?) {
//        hr_map.setData(100,50f)
        tv_measure_date.text = DatetimeUtil.formatDate(
            System.currentTimeMillis(),
            DatetimeUtil.DATE_PATTERN_A_H
        )
        mViewModel.queryDateToDate()
    }

    override fun layoutId(): Int = R.layout.fragment_heartrate_to_day

    override fun lazyLoadData() {
    }

    override fun showLoading(message: String) {
    }

    companion object {
        fun newInstance(): AllDayHeartRateToDayFragment {
            return AllDayHeartRateToDayFragment()
        }
    }
}